import type {
  BaseEntity,
  CheckedSelect,
  ID,
  IDS,
  PageQuery,
  PageResult,
  SelectTree,
} from '#/api/common';

import { requestClient } from '#/api/request';

export interface SysUser extends BaseEntity {
  userId: ID;
  deptId: string;
  deptName: string;
  deptStatus: string;
  username: string;
  nickname: number;
  email: string;
  phoneNumber: string;
  status: string;
  gender: string;
  avatar: string;
  loginIp: string;
  loginDate: string;
  remark: string;
}

const baseUrl = `/ur_biz/sys_user`;

/** 用户分页列表 */
export function listUser(query?: PageQuery) {
  return requestClient.get<PageResult<SysUser>>(`${baseUrl}/list`, {
    params: query,
  });
}

/** 查询用户详细 */
export function getUser(userId: ID) {
  return requestClient.get<SysUser>(`${baseUrl}/${userId}`);
}

/** 新增用户 */
export function addUser(data: any) {
  return requestClient.post(`${baseUrl}/add`, data);
}

/** 修改用户 */
export function editUser(data: any) {
  return requestClient.post(`${baseUrl}/edit`, data);
}

/** 删除用户 */
export function delUser(userIds: IDS) {
  return requestClient.post(`${baseUrl}/remove`, userIds);
}

/** 用户密码重置 */
export function resetPwd(id: string, password: string) {
  return requestClient.post(`${baseUrl}/reset_password`, {
    id,
    password,
  });
}

/** 用户状态修改 */
export function changeStatus(id: ID, status: string) {
  return requestClient.post(`${baseUrl}/edit_status`, {
    id,
    status,
  });
}

/** 修改授权角色 */
export function updateAuthRole(data: any) {
  return requestClient.post(`${baseUrl}/authorize_role`, data);
}

/** 查询部门选择树 */
export function deptTreeSelect(deptName: string) {
  return requestClient.get<SelectTree[]>(`${baseUrl}/dept_select_tree`, {
    params: deptName,
  });
}

/** 查询角色选择列表 */
export function roleSelect(userId?: ID) {
  return requestClient.get<CheckedSelect>(
    `${baseUrl}/role_checked_select/${userId ?? ''}`,
  );
}

/** 查询岗位选择列表 */
export function postSelect(userId?: ID) {
  return requestClient.get<CheckedSelect>(
    `${baseUrl}/post_checked_select/${userId ?? ''}`,
  );
}
